package com.example.myapplication2.Adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import com.example.myapplication2.fragment.BlankFragment2;

import java.util.ArrayList;
import java.util.HashMap;

public class FragmentAdapterDemo extends FragmentPagerAdapter {
   private ArrayList<HashMap<String, Object>> list;
    public FragmentAdapterDemo(@NonNull FragmentManager fm, ArrayList<HashMap<String, Object>> list) {
        super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
        this.list=list;
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        HashMap<String, Object> hashMap = list.get(position);
        int ioc = (int) hashMap.get("ioc");
        String text = (String) hashMap.get("text");
        //传入参数初始化碎片
        return BlankFragment2.newInstance(ioc, text);
    }

    @Override
    public int getCount() {
        return list.size();
    }
//标题
    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        String o = (String) list.get(position).get("text");
        return o;
    }
}
